home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Language/OS - Multiplatform Resource Library
/
LANGUAGE OS.iso
/
smaltalk
/
stv.lha
/
STV
/
st_v
/
util
/
STVUTIL4.ZIP
/
OPNLNK.ZIP
/
ODBCINTR.PRJ
next >
Wrap
Text File
|
1993-01-04
|
65KB
|
1,941 lines
"
******************************************************************************
Application : ODBC Interface
Date : Jan 4, 1993
Time : 20:12:45
Invoked By:
===========
Description
===========
Classes :
SQLStatement SQLConnection SQLEnvironment
SQLObject SQLColumns ODBCDLL
Methods :
#startUp defined in SystemDictionary.
#fromAddress:length: defined in Integer class.
#fromAddress: defined in Float class.
******************************************************************************
"!
"Initialize"
Smalltalk at:#SQLInfoConstants
ifAbsent: [Smalltalk at:#SQLInfoConstants put: Dictionary new].
!
"This application adds or changes methods of class Float
The class should already exist in the system.
Number variableByteSubclass: #Float
classVariableNames: ''
poolDictionaries: '' "!
Object subclass: #SQLObject
instanceVariableNames: ''
classVariableNames: ''
poolDictionaries: ''!
"This application adds or changes methods of class SystemDictionary
The class should already exist in the system.
Dictionary subclass: #SystemDictionary
instanceVariableNames: ''
classVariableNames:
'StartUpObjects ExitObjects '
poolDictionaries:
'FileConstants WinConstants CharacterConstants ' "!
"This application adds or changes methods of class Integer
The class should already exist in the system.
Number subclass: #Integer
instanceVariableNames: ''
classVariableNames: ''
poolDictionaries: '' "!
SQLObject subclass: #SQLColumns
instanceVariableNames:
'statement collection '
classVariableNames: ''
poolDictionaries: ''!
DynamicLinkLibrary variableByteSubclass: #ODBCDLL
classVariableNames: ''
poolDictionaries: ''!
SQLObject subclass: #SQLStatement
instanceVariableNames:
'connection hstmt params columns '
classVariableNames: ''
poolDictionaries: ''!
SQLObject subclass: #SQLConnection
instanceVariableNames:
'environment hdbc statements '
classVariableNames: ''
poolDictionaries:
'SQLInfoConstants '!
SQLObject subclass: #SQLEnvironment
instanceVariableNames:
'henv connections '
classVariableNames: ''
poolDictionaries: ''!
!SQLStatement class methods !
allocateOn: con
"Private"
^super new connection: con; allocate.! !
!SQLStatement methods !
allocate
"Private"
| address |
address := WinAddress allocateMemory: 4.
(ODBCLibrary SQLAllocStmt: (connection handle asParameter)
with: address asParameter) ~= SQLObject success
ifTrue: [address unlockAndFree. ^nil]
ifFalse: [
self handle: (WinLong fromAddress: address).
address unlockAndFree.
params := OrderedCollection new.
^self].!
allocateColumns
"Allocate columns for retrieving results,
then describe and bind all columns.
Asnwer an instnace of SQLColumns."
columns := SQLColumns allocateOn: self.
^columns allocate: self numberOfResultColumns.!
cancel
"Cancel the execution of the statement of the receiver."
((ODBCLibrary SQLCancel: self handle asParameter) ~= self class success)
ifTrue: [^nil]!
close
"Close the cursor and abandon all the pending results."
^self free: (SQLObject close)!
columnPrivilegesWithTableQualifer: aTableQualifier
tableOwner: aTableOwner
tableName: aTableName
columnName: searchPatternForColumnNames
"Returns a list of columns and associated privileges for one or more tables as a resut"
((ODBCLibrary SQLColumnPrivileges: self handle asParameter
with: aTableQualifier asParameter
with: aTableQualifier size asParameter
with: aTableOwner asParameter
with: aTableOwner size asParameter
with: aTableName asParameter
with: aTableName size asParameter
with: searchPatternForColumnNames asParameter
with: searchPatternForColumnNames size asParameter) ~= self class success)
ifTrue: [^nil]!
columns
"Private"
^columns!
columns: aColumns
"Private"
columns := aColumns!
columnsWithTableQualifer: aTableQualifier
tableOwner: searchPatternForTableOwner
tableName: searchPatternForTableName
columnName: searchPatternForColumnNames
"Returns the list of column names in specified tables as a result."
((ODBCLibrary SQLColumns: self handle asParameter
with: aTableQualifier asParameter
with: aTableQualifier size asParameter
with: searchPatternForTableOwner asParameter
with: searchPatternForTableOwner size asParameter
with: searchPatternForTableName asParameter
with: searchPatternForTableName size asParameter
with: searchPatternForColumnNames asParameter
with: searchPatternForColumnNames size asParameter) ~= self class success)
ifTrue: [^nil]!
connection
"Private"
^connection!
connection: aConnection
"Private"
connection := aConnection.
^self!
describeParameterAt: aMarkerNumber
"Private"
self error: ''!
Doit self drop!
drop
"Close the cursor and abandon all the pending results
and free all the memory space allocated by teh receiver."
self free: (SQLObject drop)!
execute
"Execute the prepated statements.
Ansewer nil if failed or something is wrong."
((ODBCLibrary SQLExecute: self handle asParameter) ~= self class success)
ifTrue: [^nil]!
executeDirect: aStatement
"Execute aStatement directly
Ansewer nil if failed or something is wrong."
((ODBCLibrary SQLExecDirect: self handle asParameter with: aStatement asParameter
with: aStatement size asParameter) ~= self class success)
ifTrue: [^nil].!
foreignKeys: aPrimaryKeyTableQualifier
with: aPrimaryKeyOwnerName
with: aPrimaryKeyTableName
with: aForeignKeyTableQualifier
with: aForeignKeyOwnerName
with: aMatchForeignKeyTableName
"Private"
ODBCLibrary SQLForeignKeys: self handle asParameter
with: aPrimaryKeyOwnerName asParameter
with: aPrimaryKeyOwnerName size asParameter
with: aPrimaryKeyTableName asParameter
with: aPrimaryKeyTableName size asParameter
with: aForeignKeyTableQualifier asParameter
with: aForeignKeyTableQualifier size asParameter
with: aForeignKeyOwnerName asParameter
with: aForeignKeyOwnerName size asParameter
with: aMatchForeignKeyTableName asParameter
with: aMatchForeignKeyTableName size asParameter!
free: anOption
"Private"
(self handle = nil)
ifTrue: [^self error: 'Already released.'].
((ODBCLibrary SQLFreeStmt: self handle asParameter
with: anOption asParameter) ~= self class success)
ifTrue: [^nil].
(anOption = self class close)
ifTrue: [
params do: [ :address | address unlockAndFree].
params := OrderedCollection new.
columns notNil ifTrue: [columns free. columns := nil]]
ifFalse: [
params do: [ :address | address unlockAndFree]. params := nil.
columns notNil ifTrue: [columns free. columns := nil].
connection remove: self.
self handle: nil].!
getAllTypes
"Returns information about all data types supported by the data source as a result."
^self getTypeInformation: SQLObject allTypes!
getCursorName
"Answer the cursor name assigned with the receiver"
| addressOfCursorName addressOfNumberOfBytes cursorName |
addressOfCursorName := WinAddress allocateMemory: SQLObject bufferSizeForName.
addressOfNumberOfBytes := WinAddress allocateMemory: 2.
ODBCLibrary SQLGetCursorName: self handle asParameter
with: addressOfCursorName asParameter
with: SQLObject bufferSizeForName asParameter
with: addressOfNumberOfBytes asParameter.
cursorName := String fromAddress: addressOfCursorName
length: (WinLong fromAddress: addressOfNumberOfBytes) asInteger.
addressOfCursorName unlockAndFree.
addressOfNumberOfBytes unlockAndFree.
^cursorName.!
getStatementOption: anOptionToRetroeve
"Private"
| addressOfValueOfOption valueOfOption |
addressOfValueOfOption := WinAddress allocateMemory: 4.
ODBCLibrary SQLGetStmtOption: self handle asParameter
with: anOptionToRetroeve asParameter
with: addressOfValueOfOption.
valueOfOption := (WinLong fromAddress: addressOfValueOfOption) asInteger.
addressOfValueOfOption unlockAndFree.
^valueOfOption.!
getTypeInformation: aDataTypeNumber
"Private"
((ODBCLibrary SQLGetTypeInfo: self handle asParameter
with: aDataTypeNumber asParameter) ~= self class success)
ifTrue: [^nil]!
handle
"Private"
^hstmt!
handle: aHandle
"Private"
hstmt := aHandle!
moreResults
"Private"
ODBCLibrary SQLMoreResults: self handle asParameter.!
numberOfParameters
"Private"
| numberOfParameters addressOfNumberOfParameters |
addressOfNumberOfParameters := WinAddress allocateMemory: 2.
ODBCLibrary SQLNumParams: self handles asParameter
with: addressOfNumberOfParameters asParameter.
numberOfParameters := (WinLong fromAddress: addressOfNumberOfParameters) asInteger.
addressOfNumberOfParameters unlockAndFree.
^addressOfNumberOfParameters!
numberOfResultColumns
"Answer an number of columns in the result."
"Private"
| numberOfColumns addressOfNumberOfColumns |
addressOfNumberOfColumns := WinAddress allocateMemory: 4.
ODBCLibrary SQLNumResultCols: self handle asParameter
with: addressOfNumberOfColumns asParameter.
numberOfColumns := (WinLong fromAddress: addressOfNumberOfColumns) asInteger.
addressOfNumberOfColumns unlockAndFree.
^numberOfColumns.!
parameterData
"Private"
self error: ''.!
parameterOptions
"Private"
self error: ''.!
prepare: aStatement
"Prepare aStatement for the execution"
((ODBCLibrary SQLPrepare: self handle asParameter
with: aStatement asParameter
with: aStatement size asParameter) ~= self class success)
ifTrue: [^nil]!
primaryKeys: aQualifierName
with: aSearchPatternForOwnerName
with: aSearchPatternForTableName
"Private"
ODBCLibrary SQLPrimaryKeys: self handle asParameter
with: aQualifierName asParameter
with: aQualifierName size asParameter
with: aSearchPatternForOwnerName asParameter
with: aSearchPatternForOwnerName size asParameter
with: aSearchPatternForTableName asParameter
with: aSearchPatternForTableName size asParameter.!
rowCount
"In the case of UPDATE, INSERT and DELETE,
answer an number of rows which were reflected by the execution."
| address count |
address := WinAddress allocateMemory: 4.
ODBCLibrary SQLRowCount: self handle asParameter
with: address asParameter.
count := Integer fromAddress: address length: 4.
address unlockAndFree.
^count.!
setCursorName: aName
"Associates aName with the cursor."
((ODBCLibrary SQLSetCursorName: self handle asParameter
with: aName asParameter
with: aName size asParameter) ~= self class success)
ifTrue: [^nil]!
setParameterAt: aNumber put: anObject
"Assign anObject to the parameter marker in the statement.
The parameter marker is numbered from 1 in the left-to-right order"
| address addressOfNumberOfBytes return numberOfBytes |
address := SQLObject assignBufferFor: anObject.
addressOfNumberOfBytes := WinAddress allocateMemory: 4.
addressOfNumberOfBytes at: 1 put: (anObject size).
params add: address; add: addressOfNumberOfBytes.
return := ODBCLibrary SQLSetParam: self handle asParameter
with: aNumber asParameter
with: (SQLObject cTypeFor: anObject class) asParameter
with: (SQLObject sqlTypeFor: anObject class) asParameter
with: anObject size asParameter
with: 0 asParameter
with: address asParameter
with: addressOfNumberOfBytes asParameter.
numberOfBytes :=
Integer fromAddress: addressOfNumberOfBytes length: 4.
(return ~= self class success)
ifTrue: [^nil] ifFalse: [^numberOfBytes]!
setPositionAt: anAbsolutePositionOfCursor
refresh: anOptionForRefresh lock: anOptionForLock
"Private"
ODBCLibrary SQLSetPos: self handle asParamter
with: anOptionForRefresh asParameter
with: anOptionForLock asParameter.!
tablePrivilegesWithQualifier: aTableQualifier
owner: searchPatternForOwners
name: searchPatternForNames
"Returns a list of tables and the privileges as a result."
((ODBCLibrary SQLTablePrivileges: self handle asParameter
with: aTableQualifier asParameter
with: aTableQualifier size asParameter
with: searchPatternForOwners asParameter
with: searchPatternForOwners size asParameter
with: searchPatternForNames asParameter
with: searchPatternForNames size asParameter) ~= self class success)
ifTrue: [^nil]!
tablesWithQualifier: searchPatternForQualifiers
owner: searchPatternForOwners
name: searchPatternForNames
type: listOfTableTypesToMatch
"Returns the list of tables names as a result."
((ODBCLibrary SQLTables: self handle asParameter
with: searchPatternForQualifiers asParameter
with: searchPatternForQualifiers size asParameter
with: searchPatternForOwners asParameter
with: searchPatternForOwners size asParameter
with: searchPatternForNames asParameter
with: searchPatternForNames size asParameter
with: listOfTableTypesToMatch asParameter
with: listOfTableTypesToMatch size asParameter) ~= self class success)
ifTrue: [^nil]! !
!SQLConnection class methods !
allocateOn: env
"Private"
^super new environment: env; allocate! !
!SQLConnection methods !
allocate
| address |
"Private"
address := WinAddress allocateMemory: 4.
(ODBCLibrary SQLAllocConnect: (environment handle asParameter)
with: address asParameter) ~= SQLObject success
ifTrue: [address unlockAndFree. ^nil]
ifFalse: [
self handle: (WinLong fromAddress: address).
statements := OrderedCollection new.
address unlockAndFree.
^self].!
allocateStatement
"Allocate an statement related to the receiver and
answer an instance of SQLStatement.
Answers nil if an statement could not be allocated."
| statement |
(statement := SQLStatement allocateOn: self) notNil
ifTrue: [statements add: statement. ^statement]
ifFalse: [^nil].!
commitTransaction
"Commit all the transaction including UPDATE,INSERT and DELETE
which were executed after the connection, the last commitment or
the last rollback.
Answers nil if failed"
^self transaction: (SQLObject commit)!
connectServer: aServerName user: aUserName
password: aPassword
"Establish an connection with the taget SQL server.
Answer nil if failed"
| returnCode |
returnCode := ODBCLibrary SQLConnect: self handle asParameter
with: aServerName asParameter
with: aServerName size asParameter
with: aUserName asParameter
with: aUserName size asParameter
with: aPassword asParameter
with: aPassword size asParameter.
((returnCode == (SQLObject success)) or: [returnCode == (SQLObject successWithInfo)])
ifFalse: [^nil]!
disconnect
"Close the connection"
ODBCLibrary SQLDisconnect: self handle asParameter!
driverConnect: aFullConnectionString
"Private"
self error: ''.!
environment
"Private"
^environment!
environment: env
"Private"
environment := env.
^self!
free
"Release all the memory space allocated by the receiver
and free all statements which are allocted by the receiver."
(self handle = nil)
ifTrue: [^self error: 'Already released.'].
statements do: [ :statement |
statement ~= nil ifTrue: [statement drop]].
statements := nil.
environment remove: self.
self disconnect.
ODBCLibrary SQLFreeConnect: self handle asParameter.
self handle: nil.!
getConnectionOption: anOptionToRetrieve
"Private"
| addressOfAssociatedWithOption associatedWithOption |
addressOfAssociatedWithOption := WinAddress allocateMemory: 4.
ODBCLibrary SQLGetConnectOption: self handle asParameter
with: anOptionToRetrieve asParameter
with: addressOfAssociatedWithOption.
associatedWithOption := (WinLong fromAddress: addressOfAssociatedWithOption) asInteger.
addressOfAssociatedWithOption unlockAndFree.
^associatedWithOption!
getFunction: aFunctionNumberOfInterest
"Private"
| addressOfExisits exisits |
addressOfExisits := WinAddress allocateMemory: 4.
ODBCLibrary SQLGetFunctions: self handle asParameter
with: aFunctionNumberOfInterest asParameter
with: addressOfExisits.
exisits := (WinLong fromAddress: addressOfExisits) asInteger.
addressOfExisits unlockAndFree.
exisits == (SQLObject true)
ifTrue: [^true]
ifFalse: [^false].!
getInformation
"Answer general information about the drivers and data sources
associated with the receiver"
| information id |
information := Dictionary new.
SQLInfoConstants keysDo: [ :key |
id := SQLInfoConstants at: key.
information at: key put: (self getInformationAbout: id)].
^information!
getInformationAbout: anInformationType
"Private"
| setOfStringType |
setOfStringType := #( 2 6 7 10 11 13 14 16 17 18 19 20 25 27 29 36 37 38 39 40 41 42 45 47 ) asSet.
(setOfStringType includes: anInformationType)
ifTrue: [
^self getInformationAbout: anInformationType size: SQLObject bufferSizeForName
asString: true]
ifFalse: [^self getInformationAbout: anInformationType size: 4 asString: false].!
getInformationAbout: anInformationType size: aSize asString: asString
"Private"
| addressOfInformation addressOfNumberOfBytes information |
addressOfInformation := WinAddress allocateMemory: aSize.
addressOfNumberOfBytes := WinAddress allocateMemory: 2.
ODBCLibrary SQLGetInfo: self handle asParameter
with: anInformationType asParameter
with: addressOfInformation asParameter
with: SQLObject bufferSizeForName asParameter
with: addressOfNumberOfBytes asParameter.
asString
ifTrue: [
information := String fromAddress: addressOfInformation
length: (Integer fromAddress: addressOfNumberOfBytes length: 2)]
ifFalse: [
information := Integer fromAddress: addressOfInformation
length: (Integer fromAddress: addressOfNumberOfBytes length: 2)].
addressOfInformation unlockAndFree.
addressOfNumberOfBytes unlockAndFree.
^information.!
handle
^hdbc!
handle: aHandle
hdbc := aHandle!
nativeSQL: aSQLStatementToBeTranslated
| addressOfAvailableBytes addressOfTranslatedSQLStatement
availableBytes translatedSQLStatement |
addressOfTranslatedSQLStatement := WinAddress allocateMemory: SQLObject bufferSizeForName.
addressOfAvailableBytes := WinAddress allocateMemory: 4.
ODBCLibrary SQLNativeSql: self handle asParameter
with: aSQLStatementToBeTranslated asParameter
with: aSQLStatementToBeTranslated size asParameter
with: addressOfTranslatedSQLStatement asParameter
with: SQLObject bufferSizeForName asparameter
with: addressOfAvailableBytes asParameter.
availableBytes := (WinLong fromAddress: addressOfAvailableBytes) asInteger.
availableBytes > (SQLObject bufferSizeForName)
ifTrue: [self errorOnReturnedStringIsTooLong].
translatedSQLStatement := String fromAddress: addressOfTranslatedSQLStatement.
addressOfAvailableBytes unlockAndFree.
addressOfTranslatedSQLStatement unlockAndFree.
^translatedSQLStatement.!
remove: aStatement
"Private"
statements remove: aStatement.!
rollbackTransaction
"Rollback all the transaction including UPDATE,INSERT and DELETE
which were executed after the connection, the last commitment or
the last rollback.
Answers nil if failed"
self transaction: (SQLObject rollback)!
set
"Let the receiver an active server connection"
self error: 'This API is not supported by ODBC.'!
setConnectionOption: anOptionToSet with: aValueOfOption
ODBCLibrary SQLSetConnectOption: self handle asParameter
with: anOptionToSet asParameter
with: aValueOfOption asParameter.!
transaction: aType
(ODBCLibrary SQLTransact: environment handle asParameter
with: self handle asParameter
with: aType asParameter) ~= SQLObject success
ifTrue: [^nil]! !
!SQLEnvironment class methods !
allocate
"Allocate an environment for SQL access and
answer an new instance of SQLEnvironment.
Answers ni if SQL environment could not be allocated."
^self new allocate.! !
!SQLEnvironment methods !
allocate
"Private"
| address |
address := WinAddress allocateMemory: 4.
((ODBCLibrary SQLAllocEnv: address asParameter) ~= SQLObject success)
ifTrue: [^nil].
self handle: (WinLong fromAddress: address).
address unlockAndFree.
connections := OrderedCollection new.
^self.!
allocateConnection
"Allocate an connection related to the receiver and
answer an instance of SQLConnection.
Answers nil if the receiver could not allocate an connection"
| connect |
(connect := SQLConnection allocateOn: self) notNil
ifTrue: [connections add: connect. ^connect]
ifFalse: [^nil].!
connections
"Private"
^connections!
dataSources
"Answer a dictionary of available data sources"
| dictionary returnCode addressOfDataSourceName
addressOfActualLengthOfDataSourceName
addressOfDescriptionOfDataSourceName
addressOfActualLengthOfDescription
dataSourceName descriptionOfDataSourceName |
addressOfDataSourceName
:= WinAddress allocateMemory: SQLObject bufferSizeForName.
addressOfActualLengthOfDataSourceName
:= WinAddress allocateMemory: SQLObject bufferSizeForName.
addressOfDescriptionOfDataSourceName
:= WinAddress allocateMemory: SQLObject bufferSizeForName.
addressOfActualLengthOfDescription
:= WinAddress allocateMemory: SQLObject bufferSizeForName.
dictionary := Dictionary new.
returnCode := SQLObject success.
[(returnCode == (SQLObject success)) or: [returnCode == (SQLObject successWithInfo)]]
whileTrue: [
returnCode := ODBCLibrary SQLDataSources: self handle asParameter
with: SQLObject fetchNext asParameter
with: addressOfDataSourceName asParameter
with: SQLObject bufferSizeForName asParameter
with: addressOfActualLengthOfDataSourceName asParameter
with: addressOfDescriptionOfDataSourceName asParameter
with: SQLObject bufferSizeForName asParameter
with: addressOfActualLengthOfDescription asParameter.
((returnCode == (SQLObject success)) or: [returnCode == (SQLObject successWithInfo)])
ifTrue: [
dataSourceName := String fromAddress: addressOfDataSourceName
length: (WinLong fromAddress: addressOfActualLengthOfDataSourceName) asInteger.
descriptionOfDataSourceName := String fromAddress: addressOfDescriptionOfDataSourceName
length: (WinLong fromAddress: addressOfActualLengthOfDescription) asInteger.
dictionary at: dataSourceName put: descriptionOfDataSourceName].
].
addressOfDataSourceName unlockAndFree.
addressOfActualLengthOfDataSourceName unlockAndFree.
addressOfDescriptionOfDataSourceName unlockAndFree.
addressOfActualLengthOfDescription unlockAndFree.
^dictionary.!
free
"Relese all the memory space allocated by the receiver
and free all connections which are allocated by the receiver"
(self handle = nil)
ifTrue: [^self error: 'Already released.'].
connections do: [ :connection |
connection ~= nil ifTrue: [connection free]].
connections := nil.
ODBCLibrary SQLFreeEnv: self handle asParameter.
self handle: nil.!
handle
"Private"
^henv!
handle: aHandle
"Private"
henv := aHandle!
remove: aConnection
"Private"
connections remove: aConnection! !
!SQLObject class methods !
allTypes
^0!
assignBufferFor: anObject
| address |
(anObject isKindOf: String) ifTrue:[^WinAddress copyToNonSmalltalkMemory: anObject].
(anObject isKindOf: Integer) ifTrue:[
address := WinAddress allocateMemory: 4.
(WinLong fromInteger: anObject) copyToAddress: address.
^address].
(anObject isKindOf: Float) ifTrue:[^WinAddress copyToNonSmalltalkMemory: anObject].!
bufferSizeForName
^120!
char
"SQL type code, as defined in ANSI SQL 2
(Section 14.1, Table 18) "
^1!
charInC
^self char!
close
^0!
columnCount
^1!
columnDefinitionFor: aClass
(aClass inheritsFrom: String) ifTrue:[^256].
(aClass inheritsFrom: Integer) ifTrue:[^Integer base].
(aClass inheritsFrom: Float) ifTrue:[^nil].
^nil!
columnLength
^4!
columnName
^2!
columnNulLable
^7!
columnPrecision
^5!
columnScale
^6!
columnType
^3!
commit
^0!
cTypeFor: aClass
(aClass inheritsFrom: String) ifTrue:[^self charInC].
(aClass inheritsFrom: Integer) ifTrue:[^self shortInC].
(aClass inheritsFrom: Float) ifTrue:[^self doubleInC].
^nil!
decimal
"SQL type code, as defined in ANSI SQL 2
(Section 14.1, Table 18) "
^3!
double
"SQL type code, as defined in ANSI SQL 2
(Section 14.1, Table 18) "
^8!
doubleInC
^self double!
drop
^1!
error
^-1!
false
^0!
fetchFirst
^2!
fetchNext
^1!
float
"SQL type code, as defined in ANSI SQL 2
(Section 14.1, Table 18) "
^6!
floatInC
^self real!
initialize
super initialize.
Smalltalk at:#SQLInfoConstants
ifAbsent: [Smalltalk at:#SQLInfoConstants put: Dictionary new].
SQLInfoConstants at: 'INFO_FIRST' put: 0.
SQLInfoConstants at: 'ACTIVE_CONNECTIONS' put: 0.
SQLInfoConstants at: 'ACTIVE_STATEMENTS' put: 1.
SQLInfoConstants at: 'DATA_SOURCE_NAME' put: 2.
SQLInfoConstants at: 'DRIVER_HDBC' put: 3.
SQLInfoConstants at: 'DRIVER_HENV' put: 4.
SQLInfoConstants at: 'DRIVER_HSTMT' put: 5.
SQLInfoConstants at: 'DRIVER_NAME' put: 6.
SQLInfoConstants at: 'DRIVER_VER' put: 7.
SQLInfoConstants at: 'FETCH_DIRECTION' put: 8.
SQLInfoConstants at: 'ODBC_API_CONFORMANCE' put: 9.
SQLInfoConstants at: 'ODBC_VER' put: 10.
SQLInfoConstants at: 'ROW_UPDATES' put: 11.
SQLInfoConstants at: 'ODBC_SAG_CLI_CONFORMANCE' put: 12.
SQLInfoConstants at: 'SERVER_NAME' put: 13.
SQLInfoConstants at: 'SEARCH_PATTERN_ESCAPE' put: 14.
SQLInfoConstants at: 'ODBC_SQL_CONFORMANCE' put: 15.
SQLInfoConstants at: 'DATABASE_NAME' put: 16.
SQLInfoConstants at: 'DBMS_NAME' put: 17.
SQLInfoConstants at: 'DBMS_VER' put: 18.
SQLInfoConstants at: 'ACCESSIBLE_TABLES' put: 19.
SQLInfoConstants at: 'ACCESSIBLE_PROCEDURES' put: 20.
SQLInfoConstants at: 'PROCEDURES' put: 21.
SQLInfoConstants at: 'CONCAT_NULL_BEHAVIOR' put: 22.
SQLInfoConstants at: 'CURSOR_COMMIT_BEHAVIOR' put: 23.
SQLInfoConstants at: 'CURSOR_ROLLBACK_BEHAVIOR' put: 24.
SQLInfoConstants at: 'DATA_SOURCE_READ_ONLY' put: 25.
SQLInfoConstants at: 'DEFAULT_TXN_ISOLATION' put: 26.
SQLInfoConstants at: 'EXPRESSIONS_IN_ORDERBY' put: 27.
SQLInfoConstants at: 'IDENTIFIER_CASE' put: 28.
SQLInfoConstants at: 'IDENTIFIER_QUOTE_CHAR' put: 29.
SQLInfoConstants at: 'MAX_COLUMN_NAME_LEN' put: 30.
SQLInfoConstants at: 'MAX_CURSOR_NAME_LEN' put: 31.
SQLInfoConstants at: 'MAX_OWNER_NAME_LEN' put: 32.
SQLInfoConstants at: 'MAX_PROCEDURE_NAME_LEN' put: 33.
SQLInfoConstants at: 'MAX_QUALIFIER_NAME_LEN' put: 34.
SQLInfoConstants at: 'MAX_TABLE_NAME_LEN' put: 35.
SQLInfoConstants at: 'MULT_RESULT_SETS' put: 36.
SQLInfoConstants at: 'MULTIPLE_ACTIVE_TXN' put: 37.
SQLInfoConstants at: 'OUTER_JOINS' put: 38.
SQLInfoConstants at: 'OWNER_TERM' put: 39.
SQLInfoConstants at: 'PROCEDURE_TERM' put: 40.
SQLInfoConstants at: 'QUALIFIER_NAME_SEPARATOR' put: 41.
SQLInfoConstants at: 'QUALIFIER_TERM' put: 42.
SQLInfoConstants at: 'SCROLL_CONCURRENCY' put: 43.
SQLInfoConstants at: 'SCROLL_OPTIONS' put: 44.
SQLInfoConstants at: 'TABLE_TERM' put: 45.
SQLInfoConstants at: 'TXN_CAPABLE' put: 46.
SQLInfoConstants at: 'USER_NAME' put: 47.
SQLInfoConstants at: 'CONVERT_FUNCTIONS' put: 48.
SQLInfoConstants at: 'NUMERIC_FUNCTIONS' put: 49.
SQLInfoConstants at: 'STRING_FUNCTIONS' put: 50.
SQLInfoConstants at: 'SYSTEM_FUNCTIONS' put: 51.
SQLInfoConstants at: 'TIMEDATE_FUNCTIONS' put: 52.
SQLInfoConstants at: 'CONVERT_BIGINT' put: 53.
SQLInfoConstants at: 'CONVERT_BINARY' put: 53.
SQLInfoConstants at: 'CONVERT_BIT' put: 55.
SQLInfoConstants at: 'CONVERT_CHAR' put: 56.
SQLInfoConstants at: 'CONVERT_DATE' put: 57.
SQLInfoConstants at: 'CONVERT_DECIMAL' put: 58.
SQLInfoConstants at: 'CONVERT_DOUBLE' put: 59.
SQLInfoConstants at: 'CONVERT_FLOAT' put: 60.
SQLInfoConstants at: 'CONVERT_INTEGER' put: 61.
SQLInfoConstants at: 'CONVERT_LONGVARCHAR' put: 62.
SQLInfoConstants at: 'CONVERT_NUMERIC' put: 63.
SQLInfoConstants at: 'CONVERT_REAL' put: 64.
SQLInfoConstants at: 'CONVERT_SMALLINT' put: 65.
SQLInfoConstants at: 'CONVERT_TIME' put: 66.
SQLInfoConstants at: 'CONVERT_TIMESTAMP' put: 67.
SQLInfoConstants at: 'CONVERT_TINYINT' put: 68.
SQLInfoConstants at: 'CONVERT_VARBINARY' put: 69.
SQLInfoConstants at: 'CONVERT_VARCHAR' put: 70.
SQLInfoConstants at: 'COVNERT_LONGVARBINARY' put: 71.
SQLInfoConstants at: 'TXN_ISOLATION_OPTION' put: 72.
SQLInfoConstants at: 'ODBC_SQL_OPT_IEF' put: 73.
SQLInfoConstants at: 'INFO_LAST' put: 73.
SQLInfoConstants at: 'INFO_DRIVER_START' put: 1000.!
integer
"SQL type code, as defined in ANSI SQL 2
(Section 14.1, Table 18) "
^4!
longInC
^self integer!
noDataFound
^100!
noNulls
^0!
nts
^-3!
nullable
^1!
nullableUnknown
^2!
nullData
^-1!
nullHdbc
^0!
nullHenv
^0!
nullHstmt
^0!
numeric
"SQL type code, as defined in ANSI SQL 2
(Section 14.1, Table 18) "
^2!
real
"SQL type code, as defined in ANSI SQL 2
(Section 14.1, Table 18) "
^7!
rollback
^1!
scaleFor: aClass
(aClass inheritsFrom: String) ifTrue:[^nil].
(aClass inheritsFrom: Integer) ifTrue:[^nil].
(aClass inheritsFrom: Float) ifTrue:[^nil].
^nil!
shortInC
^self smallint!
smallint
"SQL type code, as defined in ANSI SQL 2
(Section 14.1, Table 18) "
^5!
SmalltalkClassFor: aSqlType
aSqlType == (SQLObject char) ifTrue: [^String].
aSqlType == (SQLObject numeric) ifTrue: [^String].
aSqlType == (SQLObject decimal) ifTrue: [^String].
aSqlType == (SQLObject integer) ifTrue: [^Integer].
aSqlType == (SQLObject smallint) ifTrue: [^Integer].
aSqlType == (SQLObject float) ifTrue: [^Float].
aSqlType == (SQLObject real) ifTrue: [^Float].
aSqlType == (SQLObject double) ifTrue: [^Float].
aSqlType == (SQLObject varchar) ifTrue: [^String].!
sqlNullData
^-1!
sqlTypeFor: aClass
(aClass inheritsFrom: String) ifTrue:[^self char].
(aClass inheritsFrom: Integer) ifTrue:[^self integer].
(aClass inheritsFrom: Float) ifTrue:[^self double].
^nil!
success
^0!
successWithInfo
^1!
true
^1!
varchar
"SQL type code, as defined in ANSI SQL 2
(Section 14.1, Table 18) "
^12! !
!SQLObject methods !
error
"Answer an error info. related to the receiver."
| henv hdbc hstmt addressOfErrorClass addressOfNativeErrorCode
addressOfErrorMessage addressOfLengthOfAvailableMessage error |
self class == SQLEnvironment
ifTrue: [henv := self handle. hdbc := self nullHdbc. hstmt := self nullHstmt].
self class == SQLConnection
ifTrue: [henv := self environment handle. hdbc := self handle. hstmt := self class nullHstmt].
self class == SQLStatement
ifTrue: [henv := self connection environment handle.
hdbc := self connection handle. hstmt := self handle].
addressOfErrorClass := WinAddress allocateMemory: self class bufferSizeForName.
addressOfNativeErrorCode := WinAddress allocateMemory: 4.
addressOfErrorMessage := WinAddress allocateMemory: self class bufferSizeForName.
addressOfLengthOfAvailableMessage := WinAddress allocateMemory: 4.
ODBCLibrary SQLError: henv asParameter
with: hdbc asParameter
with: hstmt asParameter
with: addressOfErrorClass asParameter
with: addressOfNativeErrorCode asParameter
with: addressOfErrorMessage asParameter
with: self class bufferSizeForName asParameter
with: addressOfLengthOfAvailableMessage asParameter.
error := Dictionary new.
error at:#class put: (String fromAddress: addressOfErrorClass).
error at:#nativeErrorCode put: (WinLong fromAddress: addressOfNativeErrorCode) asInteger.
error at:#errorMessage put:(String fromAddress: addressOfErrorMessage).
addressOfErrorClass unlockAndFree.
addressOfNativeErrorCode unlockAndFree.
addressOfErrorMessage unlockAndFree.
addressOfLengthOfAvailableMessage unlockAndFree.
^error!
errorOnReturnedStringIsTooLong
self error: 'Returned String is too long'.! !
!SQLColumns class methods !
allocateOn: aStatemente
"Private"
(aStatemente columns) == nil
ifTrue: [^super new statement: aStatemente]
ifFalse: [^nil]! !
!SQLColumns methods !
actualBytesTransferredToBufferAt: aColumn
"Private"
| address |
address := (collection at: aColumn) at: #addressOfActualBytesTransferredToBuffer.
^(WinLong fromAddress: address) asInteger!
addressOfActualBytesTransferredToBufferAt: aColumn
"Private"
^(collection at: aColumn) at: #addressOfActualBytesTransferredToBuffer.!
addressOfActualBytesTransferredToBufferAt: aColumn put: anAddress
"Private"
^(collection at: aColumn) at: #addressOfActualBytesTransferredToBuffer put: anAddress.!
allocate: aNumberOfColumns
"Private"
collection := (Array new: aNumberOfColumns).
1 to: collection size
do: [ :i |
self contents at: i put: Dictionary new
].
self describeAllColumns; bindAllColumns.!
at: aColumn
"Private"
^collection at: aColumn!
bindAllColumns
"Assign storage and conversion for all columns."
| size type |
size := self size.
1 to: size
do: [ :n |
type := self dataTypeInSQLAt: n.
type == (SQLObject integer)
ifTrue: [self bindColumn: n with: SQLObject longInC with: 4].
type == (SQLObject char)
ifTrue: [self bindColumn: n with: SQLObject charInC
with: ((self maximumLengthOrPrecisionAt: n) + 1)].
type == (SQLObject numeric)
ifTrue: [self bindColumn: n with: SQLObject charInC
with: ((self maximumLengthOrPrecisionAt: n) + 1)].
type == (SQLObject decimal)
ifTrue: [self bindColumn: n with: SQLObject charInC
with: ((self maximumLengthOrPrecisionAt: n) + 1)].
type == (SQLObject smallint)
ifTrue: [self bindColumn: n with: SQLObject shortInC
with: 2].
type == (SQLObject float)
ifTrue: [self bindColumn: n with: SQLObject doubleInC
with: 8].
type == (SQLObject real)
ifTrue: [self bindColumn: n with: SQLObject doubleInC
with: 4].
type == (SQLObject double)
ifTrue: [self bindColumn: n with: SQLObject doubleInC
with: 8].
type == (SQLObject varchar)
ifTrue: [self bindColumn: n with: SQLObject charInC
with: (self maximumLengthOrPrecisionAt: n)].
].!
bindColumn: aColumnNumber
with: aDataTypeInC
with: aSizeOfBuffer
"Private"
self dataTypeInCAt: aColumnNumber put: aDataTypeInC.
self bufferAt: aColumnNumber
put: (WinAddress allocateMemory: aSizeOfBuffer).
self addressOfActualBytesTransferredToBufferAt: aColumnNumber
put: (WinAddress allocateMemory: 4).
ODBCLibrary SQLBindCol: statement handle asParameter
with: aColumnNumber asParameter
with: aDataTypeInC asParameter
with: (self bufferAt: aColumnNumber) asParameter
with: aSizeOfBuffer asParameter
with: (self addressOfActualBytesTransferredToBufferAt: aColumnNumber) asParameter.!
bufferAt: aColumn
"Private"
^(collection at: aColumn) at: #buffer!
bufferAt: aColumn put: anAddress
"Private"
^(collection at: aColumn) at: #buffer put: anAddress!
collectAllData
"Private"
| col |
col := OrderedCollection new.
1 to: self size do: [ :i |
col add: (self dataAt: i)].
^col!
collectAllName
"Private"
| col |
col := OrderedCollection new.
1 to: self size do: [ :i |
col add: (self nameAt: i)].
^col!
collectAllType
"Private"
| col |
col := OrderedCollection new.
1 to: self size do: [ :i |
col add: (self sqlTypeSymbolAt: i)].
^col!
columnAttributeMask: aColumnNumber
"Private"
| addressOfAttributeMask addressOfTypeName addressOfNumberOfCharactersInTypeName attributeMask |
addressOfAttributeMask := WinAddress allocateMemory: 2.
addressOfTypeName := WinAddress allocateMemory: SQLObject bufferSizeForName.
addressOfNumberOfCharactersInTypeName := WinAddress allocateMemory: 2.
"ODBCLibrary SQLColAttributes: statement handle asParameter
with: aColumnNumber asParameter
with: addressOfAttributeMask asParameter
with: addressOfTypeName asParameter
with: SQLObject bufferSizeForName asParameter
with: addressOfNumberOfCharactersInTypeName asParameter"
attributeMask := WinLong fromAddress: addressOfAttributeMask.
addressOfAttributeMask unlockAndFree.
addressOfTypeName unlockAndFree.
addressOfNumberOfCharactersInTypeName unlockAndFree.
^attributeMask.!
columnAttributes: aColumnNumber with: aDescribeType
"Private"
self error: 'This API is not supported by ODBC.'!
columnTypeName: aColumnNumber
"Private"
| addressOfAttributeMask addressOfTypeName addressOfNumberOfCharactersInTypeName typeName |
addressOfAttributeMask := WinAddress allocateMemory: 2.
addressOfTypeName := WinAddress allocateMemory: SQLObject bufferSizeForName.
addressOfNumberOfCharactersInTypeName := WinAddress allocateMemory: 2.
"ODBCLibrary SQLColAttributes: statement handle asParameter
with: aColumnNumber asParameter
with: addressOfAttributeMask asParameter
with: addressOfTypeName asParameter
with: SQLObject bufferSizeForName asParameter
with: addressOfNumberOfCharactersInTypeName asParameter"
typeName := String fromAddress: addressOfTypeName length: (WinLong fromAddress: addressOfNumberOfCharactersInTypeName) asInteger.
addressOfAttributeMask unlockAndFree.
addressOfTypeName unlockAndFree.
addressOfNumberOfCharactersInTypeName unlockAndFree.
^typeName.!
contents
"Private"
^collection!
contents: anCollection
"Private"
collection := anCollection!
dataAt: aColumnNumber
"Answer an object at aColumnNumber in the result."
| type |
((self actualBytesTransferredToBufferAt: aColumnNumber)
= SQLObject nullData)
ifTrue: [
((self nullableAt: aColumnNumber)
= SQLObject nullable)
ifTrue: [^'null'] ifFalse: [^'?'].
].
type := self dataTypeInSQLAt: aColumnNumber.
type == (SQLObject integer) "32bit"
ifTrue: [^Integer fromAddress: (self bufferAt: aColumnNumber) length: 4].
type == (SQLObject char)
ifTrue: [^String fromAddress: (self bufferAt: aColumnNumber)].
type == (SQLObject numeric)
ifTrue: [^nil].
type == (SQLObject decimal)
ifTrue: [^nil].
type == (SQLObject smallint)
ifTrue: [^Integer fromAddress: (self bufferAt: aColumnNumber) length: 2].
type == (SQLObject float)
ifTrue: [^nil].
type == (SQLObject real)
ifTrue: [^nil].
type == (SQLObject double)
ifTrue: [^Float fromAddress: (self bufferAt: aColumnNumber)].
type == (SQLObject varchar)
ifTrue: [^String fromAddress: (self bufferAt: aColumnNumber)].!
dataTypeInCAt: aColumn
"Private"
^(collection at: aColumn) at: #dataTypeInC!
dataTypeInCAt: aColumn put: anAddress
"Private"
^(collection at: aColumn) at: #dataTypeInC put: anAddress!
dataTypeInSQLAt: aColumn
"Answer a SQL data type at aColumn in the result."
^(collection at: aColumn) at: #dataTypeInSQL!
dataTypeInSQLAt: aColumn put: anObject
"Private"
^(collection at: aColumn) at: #dataTypeInSQL put: anObject!
describeAllColumns
"Private"
1 to: self size do: [ :n |
self describeColumn: n].!
describeColumn: aColumnNumber
"Private"
| addressOfDescriptorName addressOfNumberOfBytesAvailable addressOfDataTypeInSQL
addressOfMaximumLengthOrPrecision addressOfScale addressOfNullable |
addressOfDescriptorName := WinAddress allocateMemory: SQLObject bufferSizeForName.
addressOfNumberOfBytesAvailable := WinAddress allocateMemory: 2.
addressOfDataTypeInSQL := WinAddress allocateMemory: 2.
addressOfMaximumLengthOrPrecision := WinAddress allocateMemory: 4.
addressOfScale := WinAddress allocateMemory: 2.
addressOfNullable := WinAddress allocateMemory: 2.
ODBCLibrary SQLDescribeCol: statement handle asParameter
with: aColumnNumber asParameter
with: addressOfDescriptorName asParameter
with: SQLObject bufferSizeForName asParameter
with: addressOfNumberOfBytesAvailable asParameter
with: addressOfDataTypeInSQL asParameter
with: addressOfMaximumLengthOrPrecision asParameter
with: addressOfScale asParameter
with: addressOfNullable asParameter.
self nameAt: aColumnNumber
put: (String fromAddress: addressOfDescriptorName length: (WinLong fromAddress: addressOfNumberOfBytesAvailable) asInteger).
addressOfDescriptorName unlockAndFree. addressOfNumberOfBytesAvailable unlockAndFree.
self dataTypeInSQLAt: aColumnNumber
put: (WinLong fromAddress: addressOfDataTypeInSQL) asInteger.
addressOfDataTypeInSQL unlockAndFree.
self maximumLengthOrPrecisionAt: aColumnNumber
put: (WinLong fromAddress: addressOfMaximumLengthOrPrecision) asInteger.
addressOfMaximumLengthOrPrecision unlockAndFree.
self scaleAt: aColumnNumber
put: (WinLong fromAddress: addressOfScale) asInteger.
addressOfScale unlockAndFree.
self nullableAt: aColumnNumber
put: (WinLong fromAddress: addressOfNullable) asInteger.
addressOfNullable unlockAndFree.
^self contents!
extendedFetch: aTypeOfFetch with: aNumberOfRowsActurallyFetched
"Private"
self error: ''!
fetch
"Fetches a row of data from a result.
Answer nil if failed."
((ODBCLibrary SQLFetch: statement handle asParameter) ~= self class success)
ifTrue: [^nil]!
free
"Release all the memory space allocated by teh receiver."
1 to: collection size
do: [ :n |
(self bufferAt: n) == nil
ifTrue: []
ifFalse: [(self bufferAt: n) unlockAndFree]
].
statement columns: nil!
getObjectAt: aColumnNumber
"Private - Answer an object, picking up from output buffer."
| type size addressOfBuffer addressOfTotalBytes string totalBytes |
type := self dataTypeInSQLAt: aColumnNumber.
size := self maximumLengthOrPrecisionAt: aColumnNumber.
addressOfBuffer := WinAddress allocateMemory: size.
addressOfTotalBytes := WinAddress allocateMemory: 4.
type == (SQLObject varchar)
ifTrue: [
ODBCLibrary SQLGetData: statement handle
with: aColumnNumber asParameter
with: SQLObject char asParameter
with: addressOfBuffer asParameter
with: size asParameter
with: addressOfTotalBytes asParameter.
totalBytes := (WinLong fromAddress: addressOfTotalBytes) asInteger.
string := String fromAddress: addressOfBuffer length: totalBytes.
].
addressOfTotalBytes unlockAndFree.
addressOfBuffer unlockAndFree.
^string!
maximumLengthOrPrecisionAt: aColumn
"Answer maximum length or precision at aColumn in the result."
^(collection at: aColumn) at: #maximumLengthOrPrecision!
maximumLengthOrPrecisionAt: aColumn put: anObject
"Private"
^(collection at: aColumn) at: #maximumLengthOrPrecision put: anObject.!
nameAt: aColumn
"Answer a column name at aColumn in the result."
^(collection at: aColumn) at: #name!
nameAt: aColumn put: aName
"Private"
^(collection at: aColumn) at: #name put: aName!
nullableAt: aColumn
"Private"
^(collection at: aColumn) at: #nullable!
nullableAt: aColumn put: anObject
"Private"
^(collection at: aColumn) at: #nullable put: anObject!
scaleAt: aColumn
"Answer a scale at aColumn in the result."
^(collection at: aColumn) at: #scale!
scaleAt: aColumn put: anObject
"Private"
^(collection at: aColumn) at: #scale put: anObject!
size
"Answer number of columns in the result."
^self contents size.!
sqlTypeSymbolAt: aColumn
"Answer an instance of Symbol for SQL data type
at aColumn in the result."
| number |
number := (collection at: aColumn) at: #dataTypeInSQL.
self class char = number
ifTrue: [^#char].
self class decimal = number
ifTrue: [^#decimal].
self class double = number
ifTrue: [^#double].
self class float = number
ifTrue: [^#float].
self class integer = number
ifTrue: [^#integer].
self class real = number
ifTrue: [^#real].
self class smallint = number
ifTrue: [^#smallint].
self class varchar = number
ifTrue: [^#varchar].
^#unknown!
statement: aStatement
"Private"
statement := aStatement! !
!ODBCDLL class methods !
fileName
"Answer the receiver's file name."
^'ODBC.DLL'!
startUp
"Private - Load ODBCDLL."
ODBCLibrary := ODBCDLL open.! !
!ODBCDLL methods !
SQLAllocConnect: henv with: phdbc
"Core: SQLAllocConnect allocates memory for a connection handle
within the environment identified by henv."
<api: SQLAllocConnect ulong ulong short>
^self invalidArgument!
SQLAllocEnv: phenv
"Core: SQLAllocEnv allocates memory for an environment handle and
initializes the ODBC call-level interfaces for use by an appliction.
An applicatin must call SQLAllocEnv prior to calling any other ODBC funtion"
<api: SQLAllocEnv ulong short>
^self invalidArgument!
SQLAllocStmt: hdbc with: phstmt
"Core: SQLAllocStmt allocates memory for a statement handloe
and associates the statement handle with the connection
specified by hdbc."
<api: SQLAllocStmt ulong ulong short>
^self invalidArgument!
SQLBindCol: hstmt with: icol with: fCType with: rgbValue with: cbValueMax with: pcbValue
"Core: SQLBindCol assigns storage and conversions for a column
in a result set, iincluding:
* A storage buffer that will rceive the contents of a column of a column of data
* The length of the storage buffer
* A storage location that will receive the actual length of the column of data
returned by the fetch operation
* Data conversion
SQLBindCol can also remove binding of columns that wrer previously bound,
so that the application can call SQLGetData to retrieve data in the columns
or to simply omit columns of the result set from the set of bound colums.
Each time SQLFetch is called, the driver places the next row of the result set into the
variables specified in previous calls to SQLBindCol for each column.
To retrieve a column in portions (such as data in LONG VARCHAR types),
call SQLGetData."
<api: SQLBindCol ulong ushort short ulong long ulong short>
^self invalidArgument!
SQLCancel: hstmt
"Core: SQLCancel requests cancellation of processing for an SQL statment
and returns control to the application. If an application submits statements asychronously,
it can call SQLCancel.
Otherwise, the application cannot access SQLCancel from the Windows environment while
a request is in process. If an application calls SQLCancel for a function called synchronously,
SQLCancel has the same effect as SQLFreeStmt with the SQL_CLOSE option"
<api: SQLCancel ulong short>
^self invalidArgument!
SQLColAttributes: hstmt with: icol with: pfAttributes with: szTypeName with: cbTypeNameMax with: pcbTypeName
"Level 1: SQLColAttributes returns descriptive information -- beyond that provided
by SQLDescribeCol -- for a column in the result set."
<api: SQLColAttributes ulong ushort ulong ulong short ulong short>
^self invalidArgument!
SQLColumnPrivileges: hstmt with: szTableQualifier with: cbTableQualifier with: szTableOwner with: cbTableOwner with: szTableName with: cbTableName with: szColumnName with: cbColumnName
"Level 2: SQLColumnPrivileges returns a list of columns
and associated privileges for one or more tables.
The driver returns the information as a result set on the specified hstmt."
<api: SQLColumnPrivileges ulong struct short struct short struct short struct short short>
^self invalidArgument!
SQLColumns: hstmt with: szTableQualifier with: cbTableQualifier with: szTableOwner with: cbTableOwner with: szTableName with: cbTableName with: szColumnName with: cbColumnName
"Level 1: SQLColumns returns the list of column names in secified tables.
The driver returns this information as a result set on the specified hstmt."
<api: SQLColumns ulong struct short struct short struct short struct short short>
^self invalidArgument!
SQLConnect: hdbc with: szDSN with: cbDSN with: szUID with: cbUID with: szAuthStr with: cbAuthStr
"Core: SQLConnect loads a driver and establishes a connection to a data souce.
The connection handle references storage of all information about the connection,
including status, and error information."
<api: SQLConnect ulong struct short struct short struct short short>
^self invalidArgument!
SQLDataSources: henv with: fDirection with: szDSN with: cbDSNMax with: pcbDSN
with: szDescription with: cbDescriptionMax with: pcbDescription
"Level 2: SQLDataSources enumerates data source names"
<api: SQLDataSources ulong ushort ulong short ulong ulong short ulong short>
^self invalidArgument!
SQLDescribeCol: hstmt with: icol with: szColName with: cbColNameMax with: pcbColName with: pfSqlType with: pcbColDef with: pibScale with: pfNullable
"Core: SQLDescribeCol returns the result descriptor -- column name, type, and length --
for one column in the result set."
<api: SQLDescribeCol ulong ushort ulong short ulong ulong ulong ulong ulong short>
^self invalidArgument!
SQLDescribeParam: hstmt with: ipar with: szColName with: cbColNameMax with: pcbColName with: pfSqlType with: pcbColDef with: pibScale with: pfNullable
"Level 2: SQLDescribeParam returns the description of a parameter marker
associated with a prepared SQL statement."
<api: SQLDescribleParam ulong ushort ulong short ulong ulong ulong ulong ulong short>
^self invalidArgument!
SQLDisconnect: hdbc
"Core: SQLDisconnect closes the connection associated with a specific connection handle."
<api: SQLDisconnect ulong short>
^self invalidArgument!
SQLDriverConnect: hdbc with: hwnd with: szConnStrIn with: cbConnStrIn with: szConnStrOut with: cbConnStrOutMax with: pcbConnStrOUt with: fDriverCompletion
"Level 2: SQLDriverConnect is an alternative to SQLConnect; it supports data sources
that require connection fiformation other than teh three arguments used in SQLConnect"
<api: SQLDriverConnect ulong ulong struct short ulong short ulong ushort short>
^self invalidArgument!
SQLError: henv with: hdbc with: hstmt with: szSqlState with: pfNativeError with: szErrorMsg with: cbErrorMsgMax with: pcbErrorMsg
<api: SQLError ulong ulong ulong ulong ulong ulong short ulong short>
^self invalidArgument!
SQLExecDirect: hstmt with: szSqlStr with: cbSqlStr
<api: SQLExecDirect ulong struct long short>
^self invalidArgument!
SQLExecute: hstmt
<api: SQLExecute ulong short>
^self invalidArgument!
SQLExtendedFetch: hstmt with: fFetchType with: irow with: pcrow with: rgfRowStatus
<api: SQLExtendedFetch ulong ushort long ulong ulong short>
^self invalidArgument!
SQLFetch: hstmt
<api: SQLFetch ulong short>
^self invalidArgument!
SQLForeignKeys: hstmt with: szPkTableQualifier with: cbPkTableQualifier with: szPkTableOwner with: cbPkTableOwner with: szPkTableName with: cbPkTableName with: szFkTableQualifier with: cbFkTableQualifier with: szFkTableOwner with: cbFkTableOwner with: szFkTableName with: cbFkTableName
<api: SQLForeignKeys ulong struct short struct short struct short struct short struct short struct short short>
^self invalidArgument!
SQLFreeConnect: ulong
<api: SQLFreeConnect ulong short>
^self invalidArgument!
SQLFreeEnv: henv
<api: SQLFreeEnv ulong short>
^self invalidArgument!
SQLFreeStmt: hstmt with: fOption
<api: SQLFreeStmt ulong ushort short>
^self invalidArgument!
SQLGetConnectOption: hdbc with: fOption with: pvParam
<api: SQLGetConnectOption ulong ushort ulong short>
^self invalidArgument!
SQLGetCursorName: hstmt with: szCursor with: cbCursorMax with: pcbCursor
<api: SQLGetCursorName ulong ulong short ulong short>
^self invalidArgument!
SQLGetData: hstmt with: icol with: fCType with: rgbValue with: cbValueMax with: pcbValue
<api: SQLGetData ulong ushort short ulong long ulong short>
^self invalidArgument!
SQLGetFunctions: hdbc with: fFunction with: pfExists
<api: SQLGetFunction ulong ushort ulong short>
^self invalidArgument!
SQLGetInfo: hdbc with: fInfoType
with: rgbInfoValue with: cbInfoValueMax with: pcbInfoValue
<api: SQLGetInfo ulong ushort ulong short ulong short>
^self invalidArgument!
SQLGetStmtOption: hstmt with: fOption with: pvParam
<api: SQLGetStmtOption ulong ushort ulong short>
^self invalidArgument!
SQLGetTypeInfo: hstmt with: fSqlType
<api: SQLGetTypeInfo ulong short short>
^self invalidArgument!
SQLMoreResults: hstmt
<api: SQLMoreResults ulong short>
^self invalidArgument!
SQLNativeSql: hdbc with: szSqlStrIn with: cbSqlStrIn with: szSqlstr with: cbSqlStrMax with: pcbSqlStr
<api: SQLNativeSql ulong struct long ulong long ulong short>
^self invalidArgument!
SQLNumParams: hstmt with: pcpar
<api: SQLNumParams ulong ulong short>
^self invalidArgument!
SQLNumResultCols: hstmt with: pccol
<api: SQLNumResultCols ulong ulong short>
^self invalidArgument!
SQLParamData: hstmt with: rgbValue
<api: SQLParamData ulong ulong short>
^self invalidArgument!
SQLParamOptions: hstmt with: crow with: pirow
<api: SQLParamOption ulong ulong ulong short>
^self invalidArgument!
SQLPrepare: hstmt with: szSqlStr with: cbSqlStr
<api: SQLPrepare ulong struct long short>
^self invalidArgument!
SQLPrimaryKeys: hstmt with: szTableQualifier with: cbTableQualifier with: szTableOwner with: cbTableOwner with: szTableName with: cbTableName
<api: SQLPrimaryKeys ulong struct short struct short struct short short>
^self invalidArgument!
SQLPutData: hstmt with: rgbValue with: cbValue
<api: SQLPutData ulong ulong long short>
^self invalidArgument!
SQLRowCount: hstmt with: pcrow
<api: SQLRowCount ulong ulong short>
^self invalidArgument!
SQLSetConnectOption: hdbc with: fOption with: vParam
<api: SQLSetConnectOption ulong ushort ulong short>
^self invalidArgument!
SQLSetCursorName: hstmt with: szCursor with: cbCursor
<api: SQLSetCursorName ulong struct short short>
^self invalidArgument!
SQLSetParam: hstmt with: ipar with: fCType with: fSqlType
with: cbColDef with: ibScale with: rgbValue with: pcbValue
<api: SQLSetParam ulong ushort short short ulong short ulong ulong short>
^self invalidArgument!
SQLSetPos: hstmt with: irow with: fRefresh with: fLock
<api: SQLSetPos ulong ushort boolean boolean short>
^self invalidArgument!
SQLSetScrollOptions: hstmt with: fConcurrency with: crowKeyset with: crowRowset
<api: SQLSetScrollOptions ulong ushort long ushort short>
^self invalidArgument!
SQLSetStmtOption: hstmt with: fOption with: vParam
<api: SQLSetStmtOption ulong ushort ulong short>
^self invalidArgument!
SQLSpecialColumns: hstmt with: fColtype with: szTableQualifier with: cbTableQualifier with: szTableOwner with: cbTaleOwner with: szTableName with: cbTableName with: fScope
<api: SQLSpecialColumns ulong ushort struct short struct short struct short ushort short>
^self invalidArgument!
SQLStatistics: hstmt with: szTableQualifier with: cbTableQualifier with: szTableOwner with: cbTaleOwner with: szTableName with: cbTableName with: fUnique with: fAccuracy
<api: SQLStatistics ulong struct short struct short struct short ushort ushort short>
^self invalidArgument!
SQLTablePrivileges: hstmt
with: szTableQualifier with: cbTableQualifier
with: szTableOwner with: cbTableOwner
with: szTableName with: cbTableName
<api: SQLTablePrivileges ulong struct short struct short struct short short>
^self invalidArgument!
SQLTables: hstmt with: szTableQualifier with: cbTableQualifier
with: szTableOwner with: cbTableOwner
with: szTableName with: cbTableName
with: szTableType with: cbTableType
<api: SQLTables ulong struct short struct short struct short struct short short>
^self invalidArgument!
SQLTransact: henv with: hdbc with: fType
<api: SQLTransact ulong ulong ushort short>
^self invalidArgument! !
!SystemDictionary methods !
startUp
"Private - Initiate a Smalltalk/V session and execute
the 'go' file."
| f |
Process enableInterrupts: false.
CurrentEvents := OrderedCollection new.
WIN := WinInfo new.
WIN getIt.
KernelLibrary := WIN kernelHandle.
UserLibrary := UserDLL getHandle.
GDILibrary := GDIDLL getHandle.
KeyboardLibrary := KeyboardDLL getHandle.
VWVMLibrary := VWVMDLL open.
NationalLanguage := NationalLanguageSupport new.
Float startUp.
WinLogicalObject initObjects.
OriginalScreenExtent := Display extent.
OriginalSysFontSize := SysFont charSize.
Screen initialize.
Bitmap initialize.
Font initialize.
Font allInstancesPrim do:[:font | font initFontHandle].
Notifier initializeWindowHandles.
GraphicsTool initialize.
Smalltalk at: #OldScreenMode
put: (Array new: 5).
CursorManager initialize.
WinMsgNS := WinMessage new.
WinMsgNS contents:
(KernelLibrary globalLock:
(KernelLibrary globalAlloc: 0 bytes: 30)).
PoppedModelessWindows := OrderedCollection new.
Process enableInterrupts: true.
Processor initialize.
Sources := Array new: 3.
Disk := Directory current.
FileHandle initHandles.
DialogBox initialize.
FileDialog initialize.
Terminal font: SysFont.
CallBack startUp.
HelpManager startUp.
Icon startUp.
AbortProcDLL startUp.
ODBCDLL startUp.
self notifyStartUpObjects.
f := Disk file: 'go'.
f size > 0
ifTrue: [f fileIn; close]
ifFalse: [f close. File remove: f pathName].
Smalltalk isRunTime ifFalse: [
((Sources at: 1) isNil and: [FileHandle isThere: (File fullPathName:'sources.sml')])
ifTrue: [
Sources at: 1 put: (File pathNameReadOnly: 'sources.sml')].
(Sources at: 2) isNil ifTrue: [
Sources at: 2 put: (File pathName: 'change.log')].
(Sources at: 3) isNil ifTrue: [
Sources at: 3 put: (self openDllSource)]].
self closeSignOn.
Notifier resume.
Smalltalk isRunTime ifTrue: [
self changeRuntimeIcon].
"Opening of SmalltalkEmulator and SystemWindow is done in
Notifier resume now."
Notifier startRun! !
!Integer class methods !
fromAddress: anAddress length: aSize
"comment"
| winStruct |
winStruct := (WinStructure new: aSize).
winStruct fillFromAddress: anAddress.
aSize = 0
ifTrue: [^nil].
aSize <= 1
ifTrue: [^winStruct byteAtOffset: 0].
aSize <= 2
ifTrue: [^winStruct shortAtOffset: 0].
aSize <= 4
ifTrue: [^winStruct longAtOffset: 0].
aSize > 4
ifTrue: [^nil]! !
!Float class methods !
fromAddress: anAddress
| winDouble result |
winDouble := (WinStructure new: 8) fillFromAddress: anAddress.
result := Float fromInteger: 0.
1 to: 8 do: [ :i |
result at: i put: (winDouble contents at: i)].
^result! !
"construct application"
((Smalltalk at: #Application ifAbsent: [])
isKindOf: Class) ifTrue: [
((Smalltalk at: #Application) for:'ODBC Interface')
addClass: SQLStatement;
addClass: SQLConnection;
addClass: SQLEnvironment;
addClass: SQLObject;
addClass: SQLColumns;
addClass: ODBCDLL;
addMethod: #fromAddress:length: forClass: Integer class;
addMethod: #fromAddress: forClass: Float class;
addMethod: #startUp forClass: SystemDictionary;
comments: nil;
initCode: 'Smalltalk at:#SQLInfoConstants
ifAbsent: [Smalltalk at:#SQLInfoConstants put: Dictionary new].
';
finalizeCode: 'SQLObject initialize
';
startUpCode: '
']!
"Finalize"
SQLObject initialize
!
Transcript cr; nextPutAll: 'ODBC Interface installed'; cr. !